﻿
Imports System.Threading
Imports System.Windows.Forms
Imports System.Collections.Generic
'Imports System.collection
Imports System.Text
Imports System.Reflection
Imports System.IO



Public Class Diagnostics
    Private _panelsize As String
    Dim carseries As String
    Dim carmodel As String
    Dim shortheight As Integer = 364
    Dim fullheight As Integer = 578
    Dim buttondwn As New Point(517, 523)
    Dim buttonup As New Point(517, 304)

    Dim toppanel As New Point(5, 52)
    Dim midpanel As New Point(5, 301)
    Dim midpanelflp As New Point(3, 130)

    Public fulllist As List(Of car) = New List(Of car)
    Public resultlist As List(Of car) = New List(Of car)
    Dim BindingSource1 As New BindingSource()

    Public Property panelsize() As String
        Get
            Return _panelsize
        End Get
        Set(ByVal value As String)
            _panelsize = value

            Select Case value
                Case "step1"
                    'Top Panel
                    Panel3.Location = toppanel
                    Panel3.Height = 73 + DataGridView1.Height
                    Panel3.Visible = True

                    'Bottom Panel
                    Dim temppanel As New Point(midpanel.X, Panel3.Height + 40)
                    Panel4.Location = temppanel
                    Panel4.Visible = True
                    Panel4.Height = 130

                    'Bottom Panel Chooser
                    Panel1.Visible = False
                    Panel1.Location = midpanelflp
                    Panel2.Visible = False
                    Panel2.Location = Panel1.Location


                Case "step2"
                    'Top Panel
                    Dim temppanel As New Point(midpanel.X, Panel3.Height + 40)
                    Panel4.Location = temppanel

                    Panel3.Location = toppanel
                    Panel3.Height = 73 + DataGridView1.Height
                    Panel3.Visible = True

                    'Bottom Panel
                    Panel4.Location = temppanel
                    Panel4.Visible = True
                    Panel4.Height = 330

                    If (Panel2.Visible = False) And (Panel1.Visible = False) Then
                        Panel2.Visible = True
                    End If

                Case "connect1"
                    'Top Label
                    Label4.Visible = False
                    Label4.Text = Nothing
                    Label4.Height = 1

                    'Top Panel
                    Panel3.Height = 0
                    Panel3.Visible = False

                    'Bottom Panel
                    toppanel.Y = toppanel.Y - 30
                    Panel4.Location = toppanel
                    Panel4.Visible = True
                    Panel4.Height = 130
                    Label5.Text = "Connect your Car Kracker"


                    'Bottom Panel Chooser
                    Panel1.Visible = False
                    Panel1.Location = midpanelflp
                    Panel2.Visible = False
                    Panel2.Location = Panel1.Location




                Case "connect2"
                    'Top Label
                    Label4.Visible = False
                    Label4.Text = Nothing
                    Label4.Height = 1

                    'Top Panel
                    Panel3.Height = 0
                    Panel3.Visible = False

                    'Bottom Panel
                    Panel4.Location = toppanel
                    Panel4.Visible = True
                    Panel4.Height = 330

            End Select
            'Set Height
            Me.Height = Panel3.Height + Panel4.Height + Label4.Height + 90

            'Set Cancel Button
            Dim cnclbtn As New Point(Me.Width - 85, Me.Height - 59)
            Button1.Location = cnclbtn

        End Set
    End Property




    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim panelloc As New Point(5, 301)
        loadimg(PictureBox1, "WindowsApplication1.connectheader1.jpg")
        loadimg(PictureBox4, "WindowsApplication1.connectheader1.jpg")
        loadimg(PictureBox3, "WindowsApplication1.connectheader3.jpg")
        loadimg(PictureBox2, "WindowsApplication1.connectheader2.jpg")

        
        Dim pop As Point = MousePosition
        pop.X = pop.X - 20
        pop.Y = pop.Y - 20
        Me.Location = pop


        BindingSource1.DataSource = resultlist
        DataGridView1.DataSource = BindingSource1
        setdgridstyle(1)
        loadcarlist()
        'Me.Opacity = 0


    End Sub



    Private Function loadimg(ByVal target As Object, ByVal file As String)
        Dim tgtframe As PictureBox = CType(target, PictureBox)
        Dim executing_assembly As System.Reflection.Assembly = Assembly.GetEntryAssembly()
        Dim picture_stream As Stream
        Dim bm As Bitmap

        picture_stream = executing_assembly.GetManifestResourceStream(file)
        If Not (picture_stream Is Nothing) Then
            bm = New Bitmap(picture_stream)
            tgtframe.Image = bm
            picture_stream.Close()
        End If
        Return 0
    End Function




    Public Sub loadcarlist()


        ComboBox1.Text = "select car series..."
        ComboBox2.Text = "select car model..."
        fulllist.Add(New car("3-series", "318Ci", "e46", "M43TUB19", "", "M43", 1998, 2001))
        fulllist.Add(New car("3-series", "318i", "e46", "M43TUB19", "", "M43", 1998, 2001))
        fulllist.Add(New car("7-series", "725tds", "e38", "M51D25", "", "M51", 1995, 2001))
        fulllist.Add(New car("7-series", "728i", "e38", "M52B28", "", "M52", 1996, 2001))
        fulllist.Add(New car("7-series", "728iL", "e38", "M52B28", "", "M52", 1996, 2001))
        fulllist.Add(New car("3-series", "320i", "e46", "M52TUB20", "", "M52", 1998, 2000))
        fulllist.Add(New car("3-series", "323Ci", "e46", "M52TUB25", "", "M52", 1998, 2000))
        fulllist.Add(New car("3-series", "323i", "e46", "M52TUB25", "", "M52", 1998, 2000))
        fulllist.Add(New car("3-series", "328Ci", "e46", "M52TUB28", "", "M52", 1998, 2000))
        fulllist.Add(New car("3-series", "328i", "e46", "M52TUB28", "", "M52", 1998, 2000))
        fulllist.Add(New car("3-series", "320Ci", "e46", "M54B22", "", "M54", 2000, 2007))
        fulllist.Add(New car("3-series", "320i", "e46", "M54B22", "", "M54", 2000, 2007))
        fulllist.Add(New car("3-series", "325Ci", "e46", "M54B25", "US model", "M54", 2001, 2005))
        fulllist.Add(New car("3-series", "325Ci", "e46", "M54B25", "EUR model", "M54", 2001, 2007))
        fulllist.Add(New car("3-series", "325i", "e46", "M54B25", "US model", "M54", 2001, 2005))
        fulllist.Add(New car("3-series", "325i", "e46", "M54B25", "EUR model", "M54", 2001, 2007))
        fulllist.Add(New car("3-series", "325ti", "e46", "M54B25", "US model", "M54", 2001, 2005))
        fulllist.Add(New car("3-series", "325ti", "e46", "M54B25", "EUR model", "M54", 2001, 2007))
        fulllist.Add(New car("3-series", "325xi", "e46", "M54B25", "US model", "M54", 2001, 2005))
        fulllist.Add(New car("3-series", "325xi", "e46", "M54B25", "EUR model", "M54", 2001, 2007))
        fulllist.Add(New car("3-series", "330Ci", "e46", "M54B30", "ZHP", "M54", 2003, 2006))
        fulllist.Add(New car("3-series", "330Ci", "e46", "M54B30", "", "M54", 2000, 2007))
        fulllist.Add(New car("3-series", "330i", "e46", "M54B30", "ZHP", "M54", 2003, 2006))
        fulllist.Add(New car("3-series", "330i", "e46", "M54B30", "", "M54", 2000, 2007))
        fulllist.Add(New car("3-series", "330xi", "e46", "M54B30", "", "M54", 2000, 2007))
        fulllist.Add(New car("3-series", "325Ci", "e46", "M56B25", "SULEV US model", "M56", 2002, 2005))
        fulllist.Add(New car("3-series", "325i", "e46", "M56B25", "SULEV US model", "M56", 2002, 2005))
        fulllist.Add(New car("7-series", "730d", "e38", "M57D30", "", "M57", 1998, 2001))
        fulllist.Add(New car("7-series", "730i", "e38", "M60B30", "", "M60", 1994, 1996))
        fulllist.Add(New car("7-series", "730iL", "e38", "M60B30", "", "M60", 1994, 1996))
        fulllist.Add(New car("7-series", "740i", "e38", "M60B40", "", "M60", 1994, 1996))
        fulllist.Add(New car("7-series", "740iL", "e38", "M60B40", "", "M60", 1994, 1996))
        fulllist.Add(New car("7-series", "735i", "e38", "M62B35", "", "M62", 1994, 1997))
        fulllist.Add(New car("7-series", "735iL", "e38", "M62B35", "", "M62", 1994, 1997))
        fulllist.Add(New car("7-series", "740i", "e38", "M62B44", "", "M62", 1996, 1998))
        fulllist.Add(New car("7-series", "740iL", "e38", "M62B44", "", "M62", 1996, 1998))
        fulllist.Add(New car("7-series", "735i", "e38", "M62TUB35", "", "M62", 1998, 2001))
        fulllist.Add(New car("7-series", "735iL", "e38", "M62TUB35", "", "M62", 1998, 2001))
        fulllist.Add(New car("7-series", "740i", "e38", "M62TUB44", "", "M62", 1999, 2001))
        fulllist.Add(New car("7-series", "740iL", "e38", "M62TUB44", "", "M62", 1999, 2001))
        fulllist.Add(New car("3-series", "316i", "e46", "M67D40", "", "M67", 1998, 2001))
        fulllist.Add(New car("7-series", "740d", "e38", "M67D40", "", "M67", 1998, 2001))
        fulllist.Add(New car("7-series", "750i-iL", "e38", "M73B54", "", "M73", 1995, 1997))
        fulllist.Add(New car("7-series", "750i-iL", "e38", "M73TUB54", "", "M73", 1998, 2001))
        fulllist.Add(New car("3-series", "316i", "e46", "N42B18", "", "N42", 2001, 2004))
        fulllist.Add(New car("3-series", "316ti", "e46", "N42B18", "", "N42", 2001, 2004))
        fulllist.Add(New car("3-series", "318Ci", "e46", "N42B20", "", "N42", 2002, 2003))
        fulllist.Add(New car("3-series", "318i", "e46", "N42B20", "", "N42", 2002, 2003))
        fulllist.Add(New car("3-series", "318ti", "e46", "N42B20", "", "N42", 2002, 2003))
        fulllist.Add(New car("3-series", "316i", "e46", "N46B18", "", "N46", 2004, 2005))
        fulllist.Add(New car("3-series", "316ti", "e46", "N46B18", "", "N46", 2004, 2005))
        fulllist.Add(New car("3-series", "318Ci", "e46", "N46B20", "", "N46", 2004, 2007))
        fulllist.Add(New car("3-series", "318i", "e46", "N46B20", "", "N46", 2004, 2005))
        fulllist.Add(New car("3-series", "318ti", "e46", "N46B20", "", "N46", 2004, 2005))
        fulllist.Add(New car("3-series", "M3", "e46", "S54B32", "EUR model", "S54", 2001, 2006))
        fulllist.Add(New car("3-series", "M3", "e46", "S54B32", "US Model", "S54", 2001, 2006))
        fulllist.Add(New car("3-series", "M3 CSL", "e46", "S54B32", "", "S54", 2003, 2004))
        fulllist.Add(New car("3-series", "M3 GTR", "e46", "S54B32", "", "S54", 2001, 2005))






        For Each item In fulllist.GroupBy(Function(k) New With {Key .series = k.series})
            ComboBox1.Items.Add(item.Key.series)
        Next

    End Sub

    Private Sub Form2_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        'For i As Integer = 1 To 20
        '    Thread.Sleep(10)
        '    Me.Opacity = i / 20
        'Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged
        Dim x As ComboBox = sender
        Dim controlname As String = x.Name
        resultlist.Clear()


        If controlname = "ComboBox1" Then
            ComboBox2.Items.Clear()
            ComboBox2.Text = "select car model..."
            ComboBox2.Visible = True
            Label3.Visible = True


            Dim qry = From cars In fulllist
            qry = qry.Where(Function(d) d.series.Equals(ComboBox1.SelectedItem.ToString))

            For Each item In qry.GroupBy(Function(k) New With {Key .make = k.make})
                ComboBox2.Items.Add(item.Key.make)
            Next






        End If

        If controlname = "ComboBox2" Then
            Dim y As String
            Dim qry = From cars In fulllist
            qry = qry.Where(Function(d) d.series.Equals(ComboBox1.SelectedItem.ToString) And d.make.Equals(ComboBox2.SelectedItem.ToString)).ToList

            For Each d As car In qry
                resultlist.Add(d)
            Next
            DataGridView1.Visible = True
            DataGridView1.Height = 131

            y = Me.panelsize
            Me.panelsize = y

        End If
        BindingSource1.ResetBindings(False)







    End Sub


    Private Function setdgridstyle(ByVal sel As Integer)
        Dim i, x, y As Integer
        Dim ctrlw As Integer
        Dim roww As Integer
        Select Case sel
            Case 1
                DataGridView1.RowHeadersVisible = False

                'show Series
                i = 0
                roww = 80
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Series"
                DataGridView1.Columns(i).Width = roww

                'show Make
                i = i + 1
                roww = 80
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Make"
                DataGridView1.Columns(i).Width = roww

                'Show body
                i = i + 1
                roww = 40
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Body"
                DataGridView1.Columns(i).Width = roww

                'Hide ECU full
                i = i + 1
                roww = 0
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).Visible = False


                'Show ecu Family
                i = i + 1
                roww = 40
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "ECU"
                DataGridView1.Columns(i).Width = roww


                'Show notes
                i = i + 1
                roww = 100
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Notes"
                DataGridView1.Columns(i).Width = roww

                'Show MFG begin
                i = i + 1
                roww = 80
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Introduced"
                DataGridView1.Columns(i).Width = roww

                'Show MFG end
                i = i + 1
                roww = 80
                ctrlw = roww + ctrlw
                DataGridView1.Columns(i).HeaderText = "Last Year"
                DataGridView1.Columns(i).Width = roww

                DataGridView1.Width = ctrlw + 2
                DataGridView1.ScrollBars = ScrollBars.Vertical

                x = (Me.Width - DataGridView1.Width) / 2
                y = DataGridView1.Location.Y
                Dim dviewloc As New Point(x, y)
                DataGridView1.Location = dviewloc
            Case 2



                MsgBox("notset")

        End Select





        Return 0
    End Function



    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Panel2.Visible = False
        Panel1.Visible = True

        If Me.panelsize = "step1" Then
            Me.panelsize = "step2"
        End If
        If Me.panelsize = "connect1" Then
            Me.panelsize = "connect2"
        End If



    End Sub

    Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        Panel1.Visible = False
        Panel2.Visible = True
        If Me.panelsize = "step1" Then
            Me.panelsize = "step2"
        End If
        If Me.panelsize = "connect1" Then
            Me.panelsize = "connect2"
        End If


    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class

Public Class car
    Private _series As String
    Private _make As String
    Private _body As String
    Private _ecu As String
    Private _ecushort As String
    Private _notes As String
    Private _start As Integer
    Private _dend As Integer

    Public Sub New(ByVal series As String, ByVal make As String, ByVal body As String, ByVal ENGecu As String, ByVal notes As String, ByVal ecushort As String, ByVal start As Integer, ByVal dend As Integer)
        _series = series
        _make = make
        _body = body
        _ecu = ENGecu
        _ecushort = ecushort
        _notes = notes
        _start = start
        _dend = dend
    End Sub

    Public Property series() As String
        Get
            Return _series
        End Get
        Set(ByVal value As String)
            _series = value
        End Set
    End Property

    Public Property make() As String
        Get
            Return _make
        End Get
        Set(ByVal value As String)
            _make = value
        End Set
    End Property



    Public Property body() As String
        Get
            Return _body
        End Get
        Set(ByVal value As String)
            _body = value
        End Set
    End Property

    Public Property ecu() As String
        Get
            Return _ecu
        End Get
        Set(ByVal value As String)
            _ecu = value
        End Set
    End Property

    Public Property ecushort() As String
        Get
            Return _ecushort
        End Get
        Set(ByVal value As String)
            _ecushort = value
        End Set
    End Property


    Public Property notes() As String
        Get
            Return _notes
        End Get
        Set(ByVal value As String)
            _notes = value
        End Set
    End Property


    Public Property start() As Integer
        Get
            Return _start
        End Get
        Set(ByVal value As Integer)
            _start = value
        End Set
    End Property


    Public Property dend() As Integer
        Get
            Return _dend
        End Get
        Set(ByVal value As Integer)
            _dend = value
        End Set
    End Property


End Class






